package com.ruoyi.project.kkad.whiteip.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.kkad.whiteip.domain.WhiteIp;
import com.ruoyi.project.kkad.whiteip.service.IWhiteIpService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 白名单IPController
 * 
 * @author shixiangwen
 * @date 2020-04-13
 */
@Controller
@RequestMapping("/kkad/whiteip")
public class WhiteIpController extends BaseController
{
    private String prefix = "kkad/whiteip";

    @Autowired
    private IWhiteIpService whiteIpService;

    @RequiresPermissions("kkad:whiteip:view")
    @GetMapping()
    public String whiteip()
    {
        return prefix + "/whiteip";
    }

    /**
     * 查询白名单IP列表
     */
    @RequiresPermissions("kkad:whiteip:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WhiteIp whiteIp)
    {
        startPage();
        List<WhiteIp> list = whiteIpService.selectWhiteIpList(whiteIp);
        return getDataTable(list);
    }

    /**
     * 导出白名单IP列表
     */
    @RequiresPermissions("kkad:whiteip:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WhiteIp whiteIp)
    {
        List<WhiteIp> list = whiteIpService.selectWhiteIpList(whiteIp);
        ExcelUtil<WhiteIp> util = new ExcelUtil<WhiteIp>(WhiteIp.class);
        return util.exportExcel(list, "whiteip");
    }

    /**
     * 新增白名单IP
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存白名单IP
     */
    @RequiresPermissions("kkad:whiteip:add")
    @Log(title = "白名单IP", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WhiteIp whiteIp)
    {
        return toAjax(whiteIpService.insertWhiteIp(whiteIp));
    }

    /**
     * 修改白名单IP
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WhiteIp whiteIp = whiteIpService.selectWhiteIpById(id);
        mmap.put("whiteIp", whiteIp);
        return prefix + "/edit";
    }

    /**
     * 修改保存白名单IP
     */
    @RequiresPermissions("kkad:whiteip:edit")
    @Log(title = "白名单IP", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WhiteIp whiteIp)
    {
        return toAjax(whiteIpService.updateWhiteIp(whiteIp));
    }

    /**
     * 删除白名单IP
     */
    @RequiresPermissions("kkad:whiteip:remove")
    @Log(title = "白名单IP", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(whiteIpService.deleteWhiteIpByIds(ids));
    }
}
